package priv.winnine.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class LogAspect {

    @Around("@annotation(priv.winnine.annotation.InterfaceExecTimeLog)")
    public Object methodExecTimeLog(ProceedingJoinPoint pjp) throws Throwable {
        long begin = System.nanoTime();
        Object o = null;
        try {
            o = pjp.proceed();
        } finally {
            long end = System.nanoTime();
            log.info("{}.{}() 执行时间为: {}ms", pjp.getTarget().getClass(), pjp.getSignature().getName(), (end - begin) / 1000000);
        }
        return o;
    }

}
